import pybroker as pb
from pybroker.strategy import Strategy
from pybroker.context import ExecContext


def buy_with_stop_loss(ctx:ExecContext):
        if not ctx.long_pos():
            ctx.buy_shares = ctx.calc_target_shares(1)
            ctx.stop_loss_pct = 20
        
def buy_with_stop_loss_and_profit(ctx:ExecContext):
    if not ctx.long_pos():
        ctx.buy_shares = ctx.calc_target_shares(1)
        ctx.stop_loss_pct = 20
        ctx.stop_profit_pct = 10

class demo(Strategy):
    def __init__(self, *args, **kwargs):
        super(demo, self).__init__(*args, **kwargs)
        
        
demo1 = demo()
demo1.backtest()